﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Tailoring
{
    public partial class frmconfirm : Form
    {
        
        SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
        public frmconfirm()
        {
            InitializeComponent();
        }
        void savclient()
        {
            try
            {

                //conn = programcodes.getConnect();
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Open();
                SqlCommand cmd = new SqlCommand("insetclientinfo", conn);
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@clientId", txtid.Text);
                cmd.Parameters.AddWithValue("@name", txtname.Text);
                cmd.Parameters.AddWithValue("@mobile", txtmobile.Text);
                cmd.Parameters.AddWithValue("@address", txtaddress.Text);
                cmd.Parameters.AddWithValue("@cnic", txtcnic.Text);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                //cmd.Parameters.AddWithValue("@retday", cmbreturndays.SelectedText);
                //cmd.Parameters.AddWithValue("@speid", txtid.Text + 3);
                //cmd.Connection.Open();
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.InsertCommand = cmd;
                adapter.InsertCommand.ExecuteNonQuery();
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                this.conn.Close();

            }
        }
            void savpemaish()
        {
            try
            {
                
                //conn = programcodes.getConnect();
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn.Open();
                SqlCommand cmd = new SqlCommand("insertpemaish", conn);
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@clientId", txtid.Text);

                //cmd.Parameters.AddWithValue("@", txtname.Text);
                cmd.Parameters.AddWithValue("@lambai", txtlambai.Text);
                cmd.Parameters.AddWithValue("@chatti", txtchatti.Text);
                cmd.Parameters.AddWithValue("@tera", txttera.Text);
                cmd.Parameters.AddWithValue("@collar", txtcollar.Text);
                cmd.Parameters.AddWithValue("@asteen", txtasteen.Text);
                cmd.Parameters.AddWithValue("@daman", txtdaman.Text);
                cmd.Parameters.AddWithValue("@shalwar", txtshalwar.Text);
                cmd.Parameters.AddWithValue("@pancha", txtpancha.Text);
                //if (conn.State == ConnectionState.Open)
                //{
                //    conn.Close();
                //}
                //cmd.Connection.Open();
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.InsertCommand = cmd;
                adapter.InsertCommand.ExecuteNonQuery();
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                this.conn.Close();

            }
        
        
        }
            private void txtmobile_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar)
                        && !char.IsDigit(e.KeyChar)
                    && e.KeyChar != '-')
                {
                    e.Handled = true;
                }
            }

            private void txtcnic_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar)
                      && !char.IsDigit(e.KeyChar) && e.KeyChar != '-')
                {
                    e.Handled = true;
                }
            }

            private void txtcnic_TextChanged(object sender, EventArgs e)
            {
                string cn = txtcnic.Text;
                if (cn.Length > 15)
                {
                    toolTip1.IsBalloon = true;
                    toolTip1.ToolTipIcon = ToolTipIcon.Info;
                    toolTip1.ToolTipTitle = "Somthing Wrong with Data Entry";
                    toolTip1.Show("Only two - and 13 Digits are Allowed Select the Text and Delete And Try Again !", txtcnic, 0, -80, 2500);
                }
            }
        private void frmconfirm_Load(object sender, EventArgs e)
        {
        }
        
        public string pid { set { txtid.Text = value; } get { return txtid.Text; } }
        public string pname { set { txtname.Text = value; } get { return txtname.Text; } }
        public string pmobile { set { txtmobile.Text = value; } get { return txtmobile.Text; } }
        public string pcnic { set { txtcnic.Text = value; } get { return txtcnic.Text; } }
        public string paddress { set { txtaddress.Text = value; } get { return txtaddress.Text; } }
        public string pchati
        {
            set { txtchatti.Text=value; }
        }
        public string pcity
        {
            set { txtcity.Text = value; }
        }

        public string pdaman
        {
            set {txtdaman.Text=value; }
        }
        public string plambai
        {
            set { txtlambai.Text=value; }
        }
        public string pshalwar
        {
            set {txtshalwar.Text=value; }
        }

        public string pasteen
        {
            set { txtasteen.Text=value; }
        }
        public string ptera
        {
            set { txttera.Text=value; }
        }
        public string ppansa
        {
            set { txtpancha.Text=value; }
        }
        public string pcollor
        {
            set { txtcollar.Text=value; }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            panel1.Enabled = true;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            savclient();
            savpemaish();
            frmorder order = new frmorder();
            order.pid = pid;
            order.pname = pname;
            order.pmobile = pmobile;
            order.pcnic = pcnic;
            this.TopMost = false;
            this.Close();

            order.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            toolStripProgressBar.Visible = true;
            savclient();
            toolStripStatusLabel1.ForeColor = Color.AliceBlue;
            toolStripStatusLabel1.Text = "Saving in Progress";
            //toolStripProgressBar.PerformStep();
            savpemaish();
            toolStripStatusLabel1.ForeColor = Color.Green;
            toolStripStatusLabel1.Text = "Save Successfully !";
            toolStripProgressBar.Visible = false;
        }

        private void txtid_Leave(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Server= localhost; database=tailoringmng; integrated Security=true");
            try
            {
                conn.Open();
                string strquery = "select * from tblclientinfo where clientId=" + txtid.Text;
                SqlCommand sqlcmd = new SqlCommand(strquery, conn);
                //sqlcmd.Parameters.AddWithValue("@id", txtid.Text);
                SqlDataReader sqldreader = sqlcmd.ExecuteReader();
                if (sqldreader.HasRows)
                {
                    while (sqldreader.Read())
                    {
                        lbstatus.ForeColor = Color.Green;
                        lbstatus.Text = "This ID Exist Try Another One";
                    }
                }
                else
                {
                    lbstatus.ForeColor = Color.Green;
                    lbstatus.Text = "This ID is Available";
                }
                sqldreader.Close();
                conn.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void txtlambai_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal lambai = Convert.ToDecimal(txtlambai.Text);
                if (lambai < 13 || lambai > 50)
                {

                    e.Cancel = true;
                    txtlambai.Select(0, txtlambai.Text.Length);


                    this.errorProvider1.SetError(txtlambai, "Values Limit Exceded Specify value Between 13 And 50");

                }
            }
            catch (Exception ex) { MessageBox.Show("Error : " + ex.Message + "Collar Field is Either Empty or Something Wrong With Data Input"); }
        }

        private void txtlambai_Validated(object sender, EventArgs e)
        {

            errorProvider1.SetError(txtlambai, "");
        }

        private void txtchatti_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal chatti = Convert.ToInt32(txtchatti.Text);
                if (chatti < 18 || chatti > 45)
                {

                    e.Cancel = true;
                    txtchatti.Select(0, txtchatti.Text.Length);


                    this.errorProvider1.SetError(txtchatti, "Values Limit Exceded Specify value Between 18 And 45");

                }
            }
            catch { }
        }

        private void txtchatti_Validated(object sender, EventArgs e)
        {
            errorProvider1.SetError(txtchatti, "");
        }

        private void txtcollar_Validated(object sender, EventArgs e)
        {
            errorProvider1.SetError(txtcollar, "");
        }

        private void txtcollar_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal collar = Convert.ToInt32(txtcollar.Text);
                if (collar < 9 || collar > 25)
                {

                    e.Cancel = true;
                    txtcollar.Select(0, txtcollar.Text.Length);


                    this.errorProvider1.SetError(txtcollar, "Values Limit Exceded Specify value between 9 and 25");

                }
            }
            catch { }
        }

        private void txtasteen_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal asteen = Convert.ToInt32(txtasteen.Text);
                if (asteen < 8 || asteen > 28)
                {

                    e.Cancel = true;
                    txtasteen.Select(0, txtasteen.Text.Length);


                    this.errorProvider1.SetError(txtasteen, "Values Limit Exceded Specify value between 8 and 25");

                }
            }
            catch { }
        }

        private void txtasteen_Validated(object sender, EventArgs e)
        {
            this.errorProvider1.SetError(txtasteen, "");
        }

        private void txttera_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal tera = Convert.ToInt32(txttera.Text);
                if (tera < 8 || tera > 23)
                {

                    e.Cancel = true;
                    txttera.Select(0, txttera.Text.Length);


                    this.errorProvider1.SetError(txttera, "Values Limit Exceded Specify value between 8 and 23");

                }
            }
            catch { }
        }

        private void txttera_Validated(object sender, EventArgs e)
        {
            this.errorProvider1.SetError(txttera, "");
        }

        private void txtdaman_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal daman = Convert.ToInt32(txtdaman.Text);
                if (daman < 10 || daman > 35)
                {

                    e.Cancel = true;
                    txtdaman.Select(0, txtdaman.Text.Length);


                    this.errorProvider1.SetError(txtdaman, "Values Limit Exceded Specify value between 10 and 35");


                }
            }
            catch { }

        }

        private void txtdaman_Validated(object sender, EventArgs e)
        {
            this.errorProvider1.SetError(txtdaman, "");
        }

        private void txtpancha_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal pancha = Convert.ToInt32(txtpancha.Text);
                if (pancha < 7 || pancha > 15)
                {

                    e.Cancel = true;
                    txtpancha.Select(0, txtpancha.Text.Length);


                    this.errorProvider1.SetError(txtpancha, "Values Limit Exceded Specify value between 7 and 15");

                }
            }
            catch { }
        }

        private void txtpancha_Validated(object sender, EventArgs e)
        {
            this.errorProvider1.SetError(txtpancha, "");
        }

        private void txtshalwar_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                decimal shalwar = Convert.ToInt32(txtshalwar.Text);

                if (shalwar < 10 || shalwar > 45)
                {

                    e.Cancel = true;
                    txtshalwar.Select(0, txtshalwar.Text.Length);


                    this.errorProvider1.SetError(txtshalwar, "Values Limit Exceded Specify value between 10 and 45");

                }
            }
            catch { }
        }



        private void txtshalwar_Validated(object sender, EventArgs e)
        {
            this.errorProvider1.SetError(txtshalwar, "");
        }
    }
}
